package edu.thu.studio.ormdesigner.editor.action;

import org.eclipse.gef.editparts.ZoomListener;
import org.eclipse.gef.editparts.ZoomManager;
import org.eclipse.jface.action.Action;

import edu.thu.studio.ormdesigner.Activator;
import edu.thu.studio.ormdesigner.util.Properties;

public class ZoomAdjustAction extends Action implements ZoomListener {
    
    public static final String ID = ZoomAdjustAction.class.getName();
    
    protected ZoomManager zoomManager;
    
    public ZoomAdjustAction(ZoomManager zoomManager) {
        super(Properties.editor_zoom_adjust, Activator.getImageDescriptor(Properties.icon_zoom_adjust));
        
        this.zoomManager = zoomManager;
        zoomManager.addZoomListener(this);
        
        setToolTipText(Properties.editor_zoom_adjust);
        setId(ID);
    }
    
    public void dispose() {
        this.zoomManager.removeZoomListener(this);
    }
    
    @Override
    public void run() {
        this.zoomManager.setZoomAsText(ZoomManager.FIT_ALL);
    }
    
    @Override
    public void zoomChanged(double zoom) {
        setEnabled(true);
    }
    
}
